package com.valuegroup.smarttodo.ui.example;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

import com.valuegroup.smarttodo.R;
import com.valuegroup.smarttodo.plugins.SelectBarView;
import com.valuegroup.smarttodo.plugins.radiorealbutton.RadioRealButton;
import com.valuegroup.smarttodo.plugins.radiorealbutton.RadioRealButtonGroup;

import androidx.appcompat.app.AppCompatActivity;
import butterknife.BindView;
import butterknife.ButterKnife;

public class ExampleSegmentedButtonActivity extends AppCompatActivity {

    private Button button;
    private RadioRealButtonGroup group1;
    @BindView(R.id.barSelectRange)
    SelectBarView barSelectRange;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_example_segmented_button);
        ButterKnife.bind(this);

        button = (Button) findViewById(R.id.button1);
        group1 = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_1);

        button.setTransformationMethod(null);
        updateText(group1.getPosition());

        group1.setOnPositionChangedListener(new RadioRealButtonGroup.OnPositionChangedListener() {
            @Override
            public void onPositionChanged(RadioRealButton button, int currentPosition, int lastPosition) {
                updateText(currentPosition);
            }
        });

        group1.setOnLongClickedButtonListener(new RadioRealButtonGroup.OnLongClickedButtonListener() {
            @Override
            public boolean onLongClickedButton(RadioRealButton button, int position) {
                Toast.makeText(ExampleSegmentedButtonActivity.this, "Long Clicked! Position: " + position, Toast.LENGTH_SHORT).show();
                return false;
            }
        });

        button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                int position = group1.getPosition();
                position = ++position % group1.getNumberOfButtons();
                group1.setPosition(position);
            }
        });

        RadioRealButtonGroup group2 = (RadioRealButtonGroup) findViewById(R.id.radioRealButtonGroup_2);
        group2.setOnClickedButtonListener(new RadioRealButtonGroup.OnClickedButtonListener() {
            @Override
            public void onClickedButton(RadioRealButton button, int position) {
                Toast.makeText(ExampleSegmentedButtonActivity.this, "Position: " + position, Toast.LENGTH_SHORT).show();
            }
        });



        barSelectRange.setItems(new String[]{"月度", "季度", "年度"});
    }

    private void updateText(int position) {
        button.setText("Position: " + position);
    }
}
